<script src="/kissy/build/seed-debug.js"></script>
<script src="/kissy/src/package.js"></script>
<script>
    // test es6 generator in nodejs
    var S = KISSY;
    S.use('promise', function (S,Promise) {
        function retPromiseOk(v){
            var defer = new Promise.Defer();
            setTimeout(function(){
                defer.resolve(v+1);
            },1000);
            return defer.promise;
        }

        function retPromiseError(v){
            var defer = new Promise.Defer();
            setTimeout(function(){
                defer.reject(v);
            },1000);
            return defer.promise;
        }

        function *ok(){
            var a = yield retPromiseOk(3);
            var b = yield retPromiseOk(a);
            var c = a + b;
            return c;
        }

        function *error(){
            var a = yield retPromiseOk(3);
            var b = yield retPromiseError('wrong');
            var c = a + b;
            return c;
        }

       Promise.when(Promise.async(ok)(),function(d){
           S.log('success: '+d);
       },function(e){
           S.log('error: '+e)
       });

        Promise.when(Promise.async(error)(),function(d){
            S.log('success: '+d);
        },function(e){
            S.log('error: '+e)
        });
    });
</script>